/**
 * @constant { localStorage }
 */
const storage = window.sessionStorage;
/**
 *
 * @description 设置指定名称的localStorage
 *
 * @param {string} name
 *
 * @param {*} val
 *
 */
export function setItem(name, val) {
  storage.setItem(name, JSON.stringify(val));
}
/**
 *
 * @description 获取指定名称的localStorage
 *
 * @param {string} name
 *
 * @returns {object} 返回查询到的结果
 */
export function getItem(name) {
  const item = storage.getItem(name);
  if (!/(^\{).*(\}$)/g.test(item)) {
    return item;
  }
  return item ? JSON.parse(item) : {};
}
/**
 *
 * @description 删除指定名称localStorage
 *
 * @param {string} name
 *
 */
export function removeItem(name) {
  storage.removeItem(name);
}
/**
 *
 * @description 清除所有localStorage
 *
 */
export function clear() {
  storage.clear();
}
